/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_SCALE9SPRITE_IMPL__
#define __CC_PYTHON_IMPORT_O_SCALE9SPRITE_IMPL__

#include "python_object_scale9sprite.h"
#include "python_object_texture2d.h"
#include "python_object_textureatlas.h"
#include "python_object_spritebatchnode.h"
#include "python_object_spriteframe.h"

NS_CCPY_BEGIN
	CCNODE_OBJECT_WRAPPER_IMPL(CCScale9Sprite, CPyScale9Sprite)	

	PYCLASS_INIT_AND_BASE(CPyScale9Sprite, CPyNodeRGBA, "CCScale9Sprite", "Python CCScale9Sprite Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyScale9Sprite)
		PYCLASS_ADD_METHOD(CPyScale9Sprite, resizableSpriteWithCapInsets)
		PYCLASS_ADD_METHOD(CPyScale9Sprite, updateWithBatchNode)
		PYCLASS_ADD_METHOD_EX(CPyScale9Sprite, initWithBatchNode, METH_KEYWORDS|METH_VARARGS)
	PYCLASS_END_METHOD_DEF(CPyScale9Sprite)
	PYCLASS_BEGIN_GETSET_DEF(CPyScale9Sprite)
		PYCLASS_ADD_GET(CPyScale9Sprite, OriginalSize)
		PYCLASS_ADD_SET(CPyScale9Sprite, SpriteFrame)
		PYCLASS_ADD_GETSET(CPyScale9Sprite, PreferredSize)
		PYCLASS_ADD_GETSET(CPyScale9Sprite, CapInsets)
		PYCLASS_ADD_GETSET(CPyScale9Sprite, InsetLeft)
		PYCLASS_ADD_GETSET(CPyScale9Sprite, InsetTop)
		PYCLASS_ADD_GETSET(CPyScale9Sprite, InsetRight)
		PYCLASS_ADD_GETSET(CPyScale9Sprite, InsetBottom)
	PYCLASS_END_GETSET_DEF(CPyScale9Sprite)
	PYCLASS_IMP_INTERFACE_NOINIT(CPyScale9Sprite)

	int CPyScale9Sprite::__init__(CPyScale9Sprite *pySelf, PyObject *args, PyObject *kwds)
	{
		if( !args )
			return 0;
		static char* kwlist[] = {"fileName", "rect", "spriteFrame", "spriteFrameName", "rotated", "capInsets", NULL};
		char *filename = "";
		PyObject *py_rect = NULL;
		PyObject *py_capInsets = NULL;
		PyObject *py_spriteframe = NULL;
		char *spriteframename = "";
		bool rotated = false;
		if (!PyArg_ParseTupleAndKeywords(args,kwds,"|sOOOsb",kwlist, &filename, &py_rect, &py_capInsets, &py_spriteframe, &spriteframename, &rotated))
			return 0;
		CCScale9Sprite *spr = dynamic_cast<CCScale9Sprite *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		if(filename && strlen(filename) > 0)
		{			
			if(py_rect && py_rect != Py_None && py_capInsets && py_capInsets != Py_None)
			{
				if(!PyObject_TypeCheck(py_rect, CPyClassBase::GetTypeObject<CPyRect>()))
					return 0;
				if(!PyObject_TypeCheck(py_capInsets, CPyClassBase::GetTypeObject<CPyRect>()))
					return 0;
				CPyRect *rect = (CPyRect *)py_rect;
				CPyRect *capInsets = (CPyRect *)py_capInsets;
				spr->initWithFile(filename, rect->getCCObject(), capInsets->getCCObject());
			}else if(py_rect && py_rect != Py_None)
			{
				if(!PyObject_TypeCheck(py_rect, CPyClassBase::GetTypeObject<CPyRect>()))
					return 0;
				CPyRect *rect = (CPyRect *)py_rect;
				spr->initWithFile(filename, rect->getCCObject());
			}else if(py_capInsets && py_capInsets != Py_None)
			{
				if(!PyObject_TypeCheck(py_capInsets, CPyClassBase::GetTypeObject<CPyRect>()))
					return 0;
				CPyRect *capInsets = (CPyRect *)py_capInsets;
				spr->initWithFile(capInsets->getCCObject(), filename);
			}else
			{
				spr->initWithFile(filename);
			}
		}else if (py_spriteframe && py_spriteframe != Py_None)
		{
			if(!PyObject_TypeCheck(py_spriteframe, CPyClassBase::GetTypeObject<CPySpriteFrame>()))
				return 0;
			CPySpriteFrame *spriteframe = (CPySpriteFrame *)py_spriteframe;
			if(py_capInsets && py_capInsets != Py_None)
			{
				if(!PyObject_TypeCheck(py_capInsets, CPyClassBase::GetTypeObject<CPyRect>()))
					return 0;
				CPyRect *capInsets = (CPyRect *)py_capInsets;
				spr->initWithSpriteFrame((cocos2d::CCSpriteFrame *)spriteframe->getCCObject(), capInsets->getCCObject());
			}else
			{
				spr->initWithSpriteFrame((cocos2d::CCSpriteFrame *)spriteframe->getCCObject());
			}
			
		}else if (spriteframename && strlen(spriteframename) > 0)
		{
			if(py_capInsets && py_capInsets != Py_None)
			{
				if(!PyObject_TypeCheck(py_capInsets, CPyClassBase::GetTypeObject<CPyRect>()))
					return 0;
				CPyRect *capInsets = (CPyRect *)py_capInsets;
				spr->initWithSpriteFrameName(spriteframename, capInsets->getCCObject());
			}else
			{
				spr->initWithSpriteFrameName(spriteframename);
			}
		}
		return 0;
	}

	PYCLASS_METHOD_IMPL(CPyScale9Sprite, resizableSpriteWithCapInsets)
	{
		PyObject *pyrt = NULL;
		if( !PyArg_ParseTuple(pyArgs, "O", &pyrt) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyrt, CPyClassBase::GetTypeObject<CPyRect>()))
			Py_RETURN_NONE;
		CPyRect *rt = (CPyRect *)pyrt;
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, resizableSpriteWithCapInsets, CCScale9Sprite *, rt->getCCObject());
		if(!v)
			Py_RETURN_NONE;
		return (PyObject *)CPyCCObject::create<CPyScale9Sprite>(v);
	}

	PYCLASS_METHOD_IMPL(CPyScale9Sprite, updateWithBatchNode)
	{
		PyObject *pybatchnode = NULL;
		PyObject *pyrect = NULL;
		PyObject *pyrotated = NULL;
		PyObject *pycapInsets = NULL;
		if( !PyArg_ParseTuple(pyArgs, "OOOO", &pybatchnode, &pyrect, &pyrotated, &pycapInsets) )
			Py_RETURN_FALSE;
		if(!PyObject_TypeCheck(pybatchnode, CPyClassBase::GetTypeObject<CPySpriteBatchNode>()))
			Py_RETURN_FALSE;
		if(!PyObject_TypeCheck(pyrect, CPyClassBase::GetTypeObject<CPyRect>()))
			Py_RETURN_FALSE;
		if(!PyObject_TypeCheck(pycapInsets, CPyClassBase::GetTypeObject<CPyRect>()))
			Py_RETURN_FALSE;
		CPySpriteBatchNode *batchnode = (CPySpriteBatchNode *)pybatchnode;
		CPyRect *rect = (CPyRect *)pyrect;
		CPyRect *capInsets = (CPyRect *)pycapInsets;
		bool rotated = pyrotated == Py_True;
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, updateWithBatchNode, bool
			,(CCSpriteBatchNode *)batchnode->getCCObject()
			,rect->getCCObject()
			,rotated
			,capInsets->getCCObject());
		Py_RETURN_BOOL(v);
	}

	PYCLASS_METHOD_KW_IMPL(CPyScale9Sprite, initWithBatchNode)
	{
		if( !pyArgs )
			Py_RETURN_FALSE;
		static char* kwlist[] = {"batchnode", "rect", "rotated", "capInsets", NULL};
		PyObject *pybatchnode = NULL;
		PyObject *pyrotated = NULL;
		PyObject *pyrect = NULL;
		PyObject *pycapInsets = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"OOO|O",kwlist, &pybatchnode, &pyrect, &pycapInsets, &pyrotated))
			Py_RETURN_FALSE;
		if(!PyObject_TypeCheck(pybatchnode, CPyClassBase::GetTypeObject<CPySpriteBatchNode>()))
			Py_RETURN_FALSE;
		if(!PyObject_TypeCheck(pyrect, CPyClassBase::GetTypeObject<CPyRect>()))
			Py_RETURN_FALSE;
		if(!PyObject_TypeCheck(pycapInsets, CPyClassBase::GetTypeObject<CPyRect>()))
			Py_RETURN_FALSE;
		CPySpriteBatchNode *batchnode = (CPySpriteBatchNode *)pybatchnode;
		CPyRect *rect = (CPyRect *)pyrect;
		CPyRect *capInsets = (CPyRect *)pycapInsets;
		bool rotated = pyrotated == Py_True;

		if(pyrotated != Py_None)
		{
			CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, initWithBatchNode, bool
				,(CCSpriteBatchNode *)batchnode->getCCObject()
				,rect->getCCObject()
				,rotated
				,capInsets->getCCObject());
			Py_RETURN_BOOL(v);
		}else
		{
			CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, initWithBatchNode, bool
				,(CCSpriteBatchNode *)batchnode->getCCObject()
				,rect->getCCObject()
				,capInsets->getCCObject());
			Py_RETURN_BOOL(v);
		}
		Py_RETURN_FALSE;
	}

	PYCLASS_GET_IMPL(CPyScale9Sprite, OriginalSize)
	{
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, getOriginalSize, CCSize);
		return (PyObject *)CPySize::create(v);
	}

	PYCLASS_SET_IMPL(CPyScale9Sprite, SpriteFrame)
	{
		if(!PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPySpriteFrame>()))
			return 0;
		CPySpriteFrame *spr = (CPySpriteFrame *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(CCScale9Sprite *, CPyScale9Sprite, setSpriteFrame, (CCSpriteFrame *)spr->getCCObject());
		return 0;
	}

	PYCLASS_GET_IMPL(CPyScale9Sprite, PreferredSize)
	{
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, getPreferredSize, CCSize);
		return (PyObject *)CPySize::create(v);
	}

	PYCLASS_SET_IMPL(CPyScale9Sprite, PreferredSize)
	{
		if(!PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPySize>()))
			return 0;
		CPySize *s = (CPySize *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(CCScale9Sprite *, CPyScale9Sprite, setPreferredSize, s->getCCObject());
		return 0;
	}

	PYCLASS_GET_IMPL(CPyScale9Sprite, CapInsets)
	{
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, getCapInsets, CCRect);
		return (PyObject *)CPyRect::create(v);
	}

	PYCLASS_SET_IMPL(CPyScale9Sprite, CapInsets)
	{
		if(!PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyRect>()))
			return 0;
		CPyRect *s = (CPyRect *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(CCScale9Sprite *, CPyScale9Sprite, setCapInsets, s->getCCObject());
		return 0;
	}

	PYCLASS_GET_IMPL(CPyScale9Sprite, InsetLeft)
	{
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, getInsetLeft, float);
		return Py_BuildValue("f", v);
	}

	PYCLASS_SET_IMPL(CPyScale9Sprite, InsetLeft)
	{
		CC_METHOD_WRAPPER_SETER_RINT(CCScale9Sprite *, CPyScale9Sprite, setInsetLeft, PyFloat_AsDouble(pyValue));
		return 0;
	}

	PYCLASS_GET_IMPL(CPyScale9Sprite, InsetTop)
	{
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, getInsetTop, float);
		return Py_BuildValue("f", v);
	}

	PYCLASS_SET_IMPL(CPyScale9Sprite, InsetTop)
	{
		CC_METHOD_WRAPPER_SETER_RINT(CCScale9Sprite *, CPyScale9Sprite, setInsetTop, PyFloat_AsDouble(pyValue));
		return 0;
	}

	PYCLASS_GET_IMPL(CPyScale9Sprite, InsetRight)
	{
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, getInsetRight, float);
		return Py_BuildValue("f", v);
	}

	PYCLASS_SET_IMPL(CPyScale9Sprite, InsetRight)
	{
		CC_METHOD_WRAPPER_SETER_RINT(CCScale9Sprite *, CPyScale9Sprite, setInsetRight, PyFloat_AsDouble(pyValue));
		return 0;
	}

	PYCLASS_GET_IMPL(CPyScale9Sprite, InsetBottom)
	{
		CC_METHOD_WRAPPER_GETER(CCScale9Sprite *, CPyScale9Sprite, getInsetBottom, float);
		return Py_BuildValue("f", v);
	}

	PYCLASS_SET_IMPL(CPyScale9Sprite, InsetBottom)
	{
		CC_METHOD_WRAPPER_SETER_RINT(CCScale9Sprite *, CPyScale9Sprite, setInsetBottom, PyFloat_AsDouble(pyValue));
		return 0;
	}

NS_CCPY_END

#endif